<?php 
class mysql{
    private $con;
    public $error;
    
    public function __construct($host="localhost", $name="root", $pwd="root",$chart="utf8"){
        $this->connect($host,$name,$pwd);
        $this->chartset($chart);
    }

        private function connect($host="localhost", $name="root", $pwd="root"){
        $this->con = mysqli_connect($host, $name, $pwd);
    }//连接数据库
    
     public function db($dbName){
        mysqli_select_db($this->con, $dbName);
    }//选择数据库
    
    public function chartset($chart="utf8"){
        mysqli_set_charset($this->con, $chart);
    }//校正编码
    
    public function insert($sql){

        $result= mysqli_query($this->con, $sql);
        if(!$result){
            $error= mysqli_error($this->con);
            return $error;
        }else{
            return 1;
        }
    }//数据库插入内容
     public function select($sql){
        if(empty($sql)) {
            return array();
        }
        $result = mysqli_query($this->con, $sql);
        if(!$result) {
            $this->error = mysqli_error($this->con);
            return array();
        }
        $arr = array();
        while($row = mysqli_fetch_assoc($result)){
            $arr[] = $row;
        }
        return $arr;
    }
    
    public function update($sql){
        $reslut = mysqli_query($this->con,$sql);
        if(!$reslut) {
                 $error= mysql_error();
            }else{
                return array();
            }
    }//修改

    
    public function delect($sql){
         $result = mysqli_query($this->con,$sql);
         if(!$result) {
                 $error= mysqli_error();
            }
    }

    public function __destruct() {
        mysqli_close($this->con);
    }
    
}
